<?php

namespace App\Exports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class CommissionedExport implements FromCollection , WithHeadings, WithMapping, ShouldAutoSize
{
    private $data;
    public function __construct($data)
    {
        $this->data = $data;
    }

    public function headings() : array
    {
        return [
            '角色',
            '姓名',
            '联系方式 ',
            '留言',
            '处理状态',
            '处理人 ',
            '提交时间',
            '更新时间'
        ];
    }

    public function map($invoice): array
    {
        $aa =  [
            $invoice['role']['value'],
            $invoice['real_name'],
            $invoice['phone'],
            $invoice['content'],
            $invoice['status'] == 1 ? '未处理' : '已处理',
            $invoice['admin']['username'],
            $invoice['created_at'],
            $invoice['updated_at'],
        ];
        return $aa;
    }

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return new Collection($this->data);
    }
}
